package com.pinc.poop;

import android.content.Context;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

public class chart_unit extends LinearLayout {
	private TextView tv_times;
	private TextView tv_interval0;
	private TextView tv_interval1;
	private LinearLayout ll_chart;

	public chart_unit(Context context) {
		super(context);
		LayoutInflater li = LayoutInflater.from(context);
		li.inflate(R.layout.chart_unit, this);

		tv_times = (TextView) this.findViewById(R.id.textView_times);
		tv_interval0 = (TextView) this.findViewById(R.id.textView_interval0);
		tv_interval1 = (TextView) this.findViewById(R.id.textView_interval1);
		ll_chart = (LinearLayout) this.findViewById(R.id.linearLayout_chart);
	}

	public void setChart(int times, int total, int hour0, int hour1)
	{
		tv_times.setText(String.format("%d", times));
		tv_interval0.setText(String.format("%02d:00", hour0));
		tv_interval1.setText(String.format("%02d:00", hour1));
		int width = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 44, getResources().getDisplayMetrics());
		float ratio = (float)(times) / (float)total;
		float percent = (float) (ratio*180.0);
		int height = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, percent, getResources().getDisplayMetrics())+1;
		ll_chart.setLayoutParams(new LinearLayout.LayoutParams(width, height));
	}

}
